package io.renren.modules.api.aop;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


@Aspect
@Component
public class apiAspect {

    private static final String GATEWAY = "laiyifaa-gataway";

    @Before("execution( * io.renren.modules.api.controller.apiController.*(..))")
    public void before( ){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String invoker = request.getHeader("invoker");
        if(!GATEWAY.equals(invoker))
            throw new RuntimeException("error");

    }
}
